// 接口统一化管理
import axios from "axios";
// 引入基础路径
import { baseURL } from "../config";

// 验证token是否失效的接口
function Token() {
  return new Promise(function(resolve) {
    axios
      .get(baseURL + "app/school/hastoken")
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 报名下的找驾校
function drivingSchool(obj) {
  return new Promise(function(resolve) {
    axios
      .post(baseURL + "app/school/schoollist", obj)
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.log(err);
      });
  });
}

// 报名下找驾校筛选
function ScreenOut(obj) {
  return new Promise(function(resolve) {
    axios
      .post(baseURL + "app/school/searchschool", obj)
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 驾校详情
function schoolDetails(lid) {
  return new Promise(function(resolve) {
    axios
      .get(`${baseURL}app/school/byschool/${lid}`)
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 找驾校详情页评论
function detalisRemark(lid) {
  return new Promise(function(resolve) {
    axios
      .get(`${baseURL}app/school/byschoolpl/${lid}`)
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 驾校详情场地
function detalisSite(obj) {
  return new Promise(function(resolve) {
    axios
      // `${baseURL}app/school/byschool/${lid}`
      .post(`${baseURL}app/school/byschoolcd`, obj)
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 找教练
function findCoach(obj) {
  return new Promise(function(reslove) {
    axios
      .post(baseURL + "app/school/drillist", obj)
      .then(res => {
        reslove(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 找教练筛选
function Filtrate(obj) {
  return new Promise(function(resolve) {
    axios
      .post(baseURL + "app/school/searchdrillist", obj)
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// // 找教练详情

function CoachDetail(lid) {
  return new Promise(function(resolve) {
    axios
      .get(`${baseURL}app/school/bydril/${lid}`)
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// // 找教练评论
function coachComment(lid) {
  return new Promise(function(resolve) {
    axios
      .get(`${baseURL}app/school/bydrilPj/${lid}`)
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 找教练->教学环境
function coachEnvironment(lid) {
  return new Promise(function(resolve) {
    axios
      .get(`${baseURL}app/school/driverImgLists/${lid}`)
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 免费咨询下驾照类型
function opticalService(id) {
  return new Promise(function(resolve) {
    axios
      .get(baseURL + "app/cms/getJxCx/" + id)
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 免费咨询
function freeConsultation(obj) {
  return new Promise(function(resolve) {
    axios
      .post(baseURL + "app/cms/insertzxjl", obj)
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 免费咨询验证码
function consultPhone(phone) {
  return new Promise(function(resolve) {
    axios
      .get(`${baseURL}app/cms/insertzxjl/${phone}`)
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 在线报名
function applyOnline(obj) {
  return new Promise(function(resolve) {
    axios
      .post(baseURL + "user/app/InsertApply", obj)
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 在线报名教练
function instructor(id) {
  return new Promise(function(resolve) {
    axios
      .get(baseURL + "user/app/getJxandJl/1/" + id)
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 在线报名车型
function vehicleModel(id) {
  return new Promise(function(resolve) {
    axios
      .get(baseURL + "app/cms/getJlCx/" + id)
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 在校报名教练列表
function cordList(id) {
  return new Promise(function(resolve) {
    axios
      .get(baseURL + "app/cms/getJxList/" + id)
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 在校报名明细
function particulars(id) {
  return new Promise(function(resolve) {
    axios
      .get(baseURL + "user/app/getApplyCostDetail/" + id)
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 籍贯
function nativePlace() {
  return new Promise(function(resolve) {
    axios
      .get(baseURL + "app/cms/getGjXl")
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 在线报名->班型
function AllBanks(lid, id) {
  return new Promise(function(resolve) {
    axios
      .get(baseURL + "app/cms/getJxBj/" + lid + "/" + id)
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 在线报名->介绍人
function Introducer(lid) {
  return new Promise(function(resolve) {
    axios
      .get(baseURL + "app/cms/getJsrs/" + lid)
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 驾校图片
function DetailePhotos(lid) {
  return new Promise(function(resolve) {
    axios
      .get(baseURL + "app/school/driverImgLists/" + lid)
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 班型
function DetailsBanks(lid) {
  return new Promise(function(resolve) {
    axios
      .get(`${baseURL}app/school/byschoolbx/${lid}`)
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 班型详情
function BanksDetaols(obj) {
  return new Promise(function(resolve) {
    axios
      .get(baseURL + "app/school/getApplyCostDetail/" + obj)
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 全局搜索
function globalSSearch(obj) {
  return new Promise(function(resolve) {
    axios
      .post(baseURL + "app/school/search", obj)
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 收藏
function Collection(obj) {
  return new Promise(function(resolve) {
    axios
      .post(baseURL + "user/favorites/add", obj)
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 取消收藏
function CancelCollection(id) {
  return new Promise(function(resolve) {
    axios
      .post(baseURL + "user/favorites/remove", {
        docid: id
      })
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

export {
  Token,
  drivingSchool,
  findCoach,
  ScreenOut,
  schoolDetails,
  detalisRemark,
  Filtrate,
  detalisSite,
  CoachDetail,
  coachComment,
  coachEnvironment,
  consultPhone,
  freeConsultation,
  opticalService,
  particulars,
  instructor,
  applyOnline,
  cordList,
  vehicleModel,
  nativePlace,
  Introducer,
  DetailePhotos,
  DetailsBanks,
  BanksDetaols,
  AllBanks,
  globalSSearch,
  Collection,
  CancelCollection
};
